<?php 
namespace app\index\controller;
use think\Controller;
use think\Request;

/**
* 用户信息  展示给其他人看的
*/
class User extends Controller
{
	// 个人资料
	public function index($id)
	{
		$user = db('information')->where('userid',$id)->find();
		if ($user['zctime'] != null) {
			$user['zctime'] = date('y-m-d h:i',$user['zctime']);
		}
		if ($user['xxtime'] != null) {
			$user['xxtime'] = date('y-m-d h:i',$user['xxtime']);	
		}
		$notenum = db('note')->where('uid',$id)->count();
		$talknum = db('user_talk')->where('uid',$id)->count();
		$this->assign('user',$user);
		$this->assign('notenum',$notenum);
		$this->assign('talknum',$talknum);
		return $this->fetch();
	}
	// 自己发的帖子
	public function post($id)
	{
		$user = db('information')->where('userid',$id)->find();
		$note = db('note')->where(['uid'=>$id,'status'=>'0'])->order('id','desc')->select();
		$this->assign('note',$note);
		$this->assign('user',$user);
		return $this->fetch();
	}
	// 控制control  有被封的帖子 解封solution
	public function control($id)
	{
		$user = db('information')->where('userid',$id)->find();
		$note = db('note')->where('status','1')->select();
		foreach ($note as &$val) {
            $val['name'] = db('information')->where('userid', $val['uid'])->find()['name'];
            $val['time'] = date('y-m-d h:i',$val['time']);
        }
		$this->assign('user',$user);
		$this->assign('note',$note);
		return $this->fetch();
	}
}